<template>
  <div class="xzuwh">
    <div class="table-module">
      <el-card>
        <div class="btn-group">
          <el-button type="primary" @click="addRecord">添加协作组</el-button>
          <el-button type="danger" @click="deleteRecord">删除协作组</el-button>
        </div>
        <el-table
          @selection-change="handleSelectionChange"
          :data="tableData"
          border
          style="width: 100%">
          <el-table-column
            type="selection"
            width="55">
          </el-table-column>
          <el-table-column
            label="话题"
            prop="Name"
            width="50">
          </el-table-column>
          <el-table-column
            prop="GroupLeader"
            label="组长"
            width="180">
          </el-table-column>
          <el-table-column
            prop="Remark"
            label="备注"
            width="180">
          </el-table-column>
          <el-table-column
            label="操作"
            width="120">
            <template slot-scope="scope">
              <el-button
                v-if="true"
                @click.native.prevent="handleClick(scope.$index, tableData)"
                type="text"
                size="small">
                修改
              </el-button>
            </template>
          </el-table-column>
        </el-table>
      </el-card>
    </div>
    <div class="dialog-module">
      <el-dialog title="协作组" :visible.sync="dialogAddVisible" custom-class="add-dialog">
        <div class="content">
          <div class="content-item">
            <span>话题：</span>
            <el-input v-model="value1" placeholder="请输入内容"></el-input>
          </div>
          <div class="content-item">
            <span>组长：</span>
            <el-select v-model="value2" placeholder="请选择">
              <el-option
                v-for="item in value2options"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
          </div>
          <div class="content-item">
            <span>组员：</span>
            <el-select v-model="value3"  multiple collapse-tags placeholder="请选择">
              <el-option
                v-for="item in value3options"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
          </div>
          <div class="content-item">
            <span style="height: 50px; line-height: 50px; display: inline-block">备注：</span>
            <el-input
              type="textarea"
              :rows="2"
              placeholder="请输入内容"
              v-model="value4">
            </el-input>
          </div>
        </div>
        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogAddVisible = false">取 消</el-button>
          <el-button type="primary" @click="saveParams">保存退出</el-button>
        </div>
      </el-dialog>
      <!--再加一个用以前的弹框来响应下一步-->
    </div>
    <div class="dialog-module">
      <el-dialog title="协作组" :visible.sync="dialogEditVisible" custom-class="add-dialog">
        <div class="content">
          <div class="content-item">
            <span>话题：</span>
            <el-input v-model="value1" placeholder="请输入内容"></el-input>
          </div>
          <div class="content-item">
            <span>组长：</span>
            <el-select v-model="value2" placeholder="请选择">
              <el-option
                v-for="item in value2options"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
          </div>
          <div class="content-item">
            <span>组员：</span>
            <el-select v-model="value3"  multiple collapse-tags placeholder="请选择">
              <el-option
                v-for="item in value3options"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
          </div>
          <div class="content-item">
            <span style="height: 50px; line-height: 50px; display: inline-block">备注：</span>
            <el-input
              type="textarea"
              :rows="2"
              placeholder="请输入内容"
              v-model="value4">
            </el-input>
          </div>
        </div>
        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogEditVisible = false">取 消</el-button>
          <el-button type="primary" @click="editTableRow">保存退出</el-button>
        </div>
      </el-dialog>
      <!--再加一个用以前的弹框来响应下一步-->
    </div>
  </div>
</template>

<style lang="scss" scoped>
  .xzuwh {
    .selected-module {
      .el-icon-search {
        font-size: 34px;
      }
      .select-item {
        display: inline-block;
        margin-right: 20px;
        .el-input, .el-select {
          display: inline-block;
          width: 150px;
        }
      }
      .btn-group {
        float: right;
      }
    }
    .table-module {
      .btn-group {
        margin-bottom: 10px;
      }
    }
    .dialog-module {
      .content {
        .el-icon-search {
          font-size: 34px;
          margin-right: 20px;
        }
        .content-item {
          /*display: inline-block;*/
          margin-top: 10px;
          .el-select, .el-input {
            display: inline-block;
            width: 150px;
          }
          .el-textarea {
            width: 300px;
          }
        }
      }
    }
  }
</style>

<script>
  import {getToken} from "../../utils/auth";
  export default {
    data() {
      return {
        multipleSelection: '', // 选择框选中的数据
        multipleSelectionIdArr: [],
        editIndex: '',
        value1: '',
        value2: '',
        value2options: [
          {
            value: '张哲',
            label: '张哲'
          },
          {
            value: '小眼',
            label: '小眼'
          }
        ],
        value3: [],
        value3options: [
          {
            value: '张哲',
            label: '张哲'
          },
          {
            value: '小眼',
            label: '小眼'
          }
        ],
        value4: '',
        processName: '',
        tableData: [],
        startData: '',
        endData: '',
        dialogAddVisible: false,
        dialogEditVisible: false,
        dialogValue1: '',
        dialogValue1Options: [
          {
            value: '选项1',
            label: '黄金糕'
          }, {
            value: '选项2',
            label: '双皮奶'
          }, {
            value: '选项3',
            label: '蚵仔煎'
          }, {
            value: '选项4',
            label: '龙须面'
          }, {
            value: '选项5',
            label: '北京烤鸭'
          }
        ],
        currentpage: 1,
        showPage: 10,
      }
    },
    methods: {
      handleClick(index, tableData) {
        this.dialogEditVisible = true
        this.editIndex = index
      },
      addRecord() {
        this.dialogAddVisible = true
      },
      async deleteRecord() {
        if (this.multipleSelectionIdArr.length !== 0) {
          let params = {
            token: getToken(),
            id: this.multipleSelectionIdArr.join('')
          }
          let res = await this.axios.post('v1/jsbk/case/del', params)
          this.loadTableData()
        }
        // 清空
        // this.multipleSelectionIdArr = []
      },
      async saveParams() {
        this.dialogAddVisible = false
        let params = {
          token: getToken(),
          name: this.value1,
          groupLeader: this.value2,
          groupMember: this.value3,
          remark: this.value4,
        }
        let res = await this.axios.post('v1/xzz/add_action', params)
        if (res.data.code === 200) {
          this.$message({
            message: '保存成功',
            type: 'success'
          });
          this.loadTableData()
        }
      },
      async loadTableData() {
        let params = {
          token: getToken(),
          index: this.currentpage,
          pagemax: this.showPage
        }
        let res = await this.axios.get('v1/xzz/getdata', {params})
        console.log(res)
        this.tableData = res.data.data
      },
      async editTableRow() {
        this.dialogEditVisible = false
        let params = {
          token: getToken(),
          id: this.value1,
          name: this.value2,
          groupLeader: this.value3,
          groupMember: this.value4,
          remark: this.value5,
        }
        let res = await this.axios.post('v1/xzz/edit_action', params)
        // console.log(res)
        if (res.data.code === 200) {
          this.$message({
            message: '修改成功',
            type: 'success'
          });
        }
      },
      handleSelectionChange(val) {
        // console.log(val)
        this.multipleSelection = val
        this.multipleSelectionIdArr = this.multipleSelection.map(item => item.Id)
      }
    },
    created() {
      this.loadTableData()
    }
  }
</script>
